package com.stylefeng.guns.modular.pay.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.stylefeng.guns.core.base.controller.BaseController;
import com.stylefeng.guns.core.log.LogObjectHolder;
import com.stylefeng.guns.modular.pay.model.SubBankCode;
import com.stylefeng.guns.modular.pay.service.ISubBankCodeService;

/**
 * 银行编码控制器
 *
 * @author fengshuonan
 * @Date 2018-09-07 14:23:00
 */
@Controller
@RequestMapping("/subBankCode")
public class SubBankCodeController extends BaseController {

    private String PREFIX = "/pay/subBankCode/";

    @Autowired
    private ISubBankCodeService subBankCodeService;

    /**
     * 跳转到银行编码首页
     */
    @RequestMapping("")
    public String index() {
        return PREFIX + "subBankCode.html";
    }

    /**
     * 跳转到添加银行编码
     */
    @RequestMapping("/subBankCode_add")
    public String subBankCodeAdd() {
        return PREFIX + "subBankCode_add.html";
    }

    /**
     * 跳转到修改银行编码
     */
    @RequestMapping("/subBankCode_update/{subBankCodeId}")
    public String subBankCodeUpdate(@PathVariable Integer subBankCodeId, Model model) {
        SubBankCode subBankCode = subBankCodeService.selectById(subBankCodeId);
        model.addAttribute("item",subBankCode);
        LogObjectHolder.me().set(subBankCode);
        return PREFIX + "subBankCode_edit.html";
    }

    /**
     * 获取银行编码列表
     */
    @RequestMapping(value = "/list")
    @ResponseBody
    public Object list(String condition) {
        return subBankCodeService.selectList(null);
    }

    /**
     * 新增银行编码
     */
    @RequestMapping(value = "/add")
    @ResponseBody
    public Object add(SubBankCode subBankCode) {
        subBankCodeService.insert(subBankCode);
        return SUCCESS_TIP;
    }

    /**
     * 删除银行编码
     */
    @RequestMapping(value = "/delete")
    @ResponseBody
    public Object delete(@RequestParam Integer subBankCodeId) {
        subBankCodeService.deleteById(subBankCodeId);
        return SUCCESS_TIP;
    }

    /**
     * 修改银行编码
     */
    @RequestMapping(value = "/update")
    @ResponseBody
    public Object update(SubBankCode subBankCode) {
        subBankCodeService.updateById(subBankCode);
        return SUCCESS_TIP;
    }

    /**
     * 银行编码详情
     */
    @RequestMapping(value = "/detail/{subBankCodeId}")
    @ResponseBody
    public Object detail(@PathVariable("subBankCodeId") Integer subBankCodeId) {
        return subBankCodeService.selectById(subBankCodeId);
    }
}
